Xbasic
SQL::QueryParse Method
Syntax
Result_Flag as L = Parse([SQLStatement as C])
Arguments
- Result_Flag
TRUE (.T.) if the operation was successful; otherwise FALSE (.F.).
- SQL::Query
A SQL::Query object created with a DIM statement.
- SQLStatement
Optional. A Portable SQL statement.
Description
Parse the SQLStatement passed (or the value previously set into the SQLStatement property).
Discussion
The Parse()parses the passed SQL_Statement (or the value previously set into the SQL::Query.SQLStatement property).
Example
dim conn as SQL::Connection dim connString as C dim qry as SQL::Query connString = "{A5API='Access', FileName='c:\program files\a5v7\mdbfiles\alphasports.mdb'}" ? conn.open(connString) = .T. ? qry.parse("Select * from Customers") = .T.
This script shows the difference between the .SelectTableReferences and .TableReferences properties of the SQL::Query object.
dim q as SQL::query ? q.parse("select item from table1 t1 join table2 t2 on t1.a = t2.a join table3 t3 on t2.a = t3.a and t3.x in (select z from table4 t4 ) where x in (select y from z)") = .T. ? q.selecttablereferences.Count = 3 ? q.selecttablereferences1 = Alias = "t1" +Join. Name = "table1" Owner = "" TokenTypeName = "SelectTableReference" ? q.selecttablereferences2 = Alias = "t2" +Join. Name = "table2" Owner = "" TokenTypeName = "SelectTableReference" ? q.selecttablereferences3 = Alias = "t3" +Join. Name = "table3" Owner = "" TokenTypeName = "SelectTableReference" ? q.tablereferences.Count = 5 ? q.tablereferences1 = Alias = "t1" +Join. Name = "table1" Owner = "" TokenTypeName = "SelectTableReference" ? q.tablereferences2 = Alias = "t2" +Join. Name = "table2" Owner = "" TokenTypeName = "SelectTableReference" ? q.tablereferences3 = Alias = "t3" +Join. Name = "table3" Owner = "" TokenTypeName = "SelectTableReference" ?q.tablereferences4 = Alias = "t4" +Join. Name = "table4" Owner = "" TokenTypeName = "SelectTableReference" ? q.tablereferences5 = Alias = "" +Join. Name = "z" Owner = "" TokenTypeName = "SelectTableReference"
Do the same process on the nested subselect.
SubSelect = q.where.operand2 ? subselect.selecttablereferences.Count = 1 ? subselect.selecttablereferences1 = Alias = "" +Join. Name = "z" Owner = "" TokenTypeName = "SelectTableReference" ? subselect.tablereferences.Count = 1 ? subselect.tablereferences1 = Alias = "" +Join. Name = "z" Owner = "" TokenTypeName = "SelectTableReference"
A Script to Manually Build a Query
This simple example constructs a query as a builder interface would likely do it. It adds tables and columns to a declared query.
dim q as SQL::query dim c as SQL::query::Columnreference dim option as N SQLTestStatement = <<%SQL% SELECT distinct c.Name as CustomerName, IH.Due_Date, II.Part_Number, P.Description FROM Customer C, Invoice_Header IH, Invoice_Item II, Part p left outer join part_description pd on pd.name = p.name %SQL%
Reset the query and parse a string.
q.Reset() q.SQLStatement = SQLTestStatement q.Parse() q.execute(c)
See Also